package cn.tedu._06interceptor.base.config;

import cn.tedu._06interceptor.base.interceptors.MyInterceptor1;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 实现 WebMvcConfigurer接口  Spring MVC的标准化配置接口
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器并添加拦截路径
        //策略1:拦截所有路径
        //registry.addInterceptor(new MyInterceptor1())
        //        .addPathPatterns("/v1/**");

        //策略2:拦截指定的多个请求,比如拦截注册和登录2个请求;
        //registry.addInterceptor(new MyInterceptor1())
        //        .addPathPatterns("/v1/user/reg", "/v1/user/login");

        //测录3:排除指定的请求,比如:拦截用户模块中除了注册之外的所有请求;
        registry.addInterceptor(new MyInterceptor1())
                .addPathPatterns("/v1/user/**")
                .excludePathPatterns("/v1/user/reg");
    }
}
